package com.baoxin.chenxixc4coach.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.baoxin.chenxixc4coach.R;


public class LoadingDialog extends Dialog {
    public LoadingDialog(@NonNull Context context) {
        super(context);
    }

    public LoadingDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    public static class Builder {
        private Context context;
        private String message;
        private boolean isShowMessage = true;
        private boolean isCancelable = false;
        private boolean isCancleOutside = false;

        public Builder(Context context) {
            this.context = context;
        }

        public Builder setMessage(String message) {
            this.message = message;
            return this;
        }

        public Builder setShowMessage(boolean isShowMessage) {
            this.isShowMessage = isShowMessage;
            return this;
        }

        public Builder setCancelable(boolean isCancelable) {
            this.isCancelable = isCancelable;
            return this;
        }

        public Builder setCancelOutside(boolean isCancleOutside) {
            this.isCancleOutside = isCancleOutside;
            return this;
        }

        public LoadingDialog create() {
            View view = LayoutInflater.from(context).inflate(R.layout.loading_layout, null);
            LoadingDialog loadingDialog = new LoadingDialog(context, R.style.MyDialogStyle);
            TextView msgTx = view.findViewById(R.id.tipTextView);
            if (isShowMessage) {
                msgTx.setText(message);
            } else {
                msgTx.setVisibility(View.GONE);
            }
            loadingDialog.setContentView(view);
            loadingDialog.setCancelable(isCancelable);
            loadingDialog.setCanceledOnTouchOutside(isCancleOutside);
            return loadingDialog;
        }
    }


}
